﻿Imports System.IO
Module BinaryReadWrite

    Friend Sub GetFilename()
        Try
            Dim scc As BinaryReader = New BinaryReader(File.Open(FileFound, FileMode.Open))
            SaveFileByte = ""
            SaveFile = ""
            Dim offset1 As Integer = 1042
            'get game name
            Do Until SaveFileByte = "0" Or SaveFileByte = "00"

                scc.BaseStream.Seek(offset1, SeekOrigin.Begin)
                SaveFileByte = Hex(scc.ReadByte())
                If GameNameByte = "0" Or GameNameByte = "00" Then
                    Exit Do
                Else
                    SaveFile = SaveFile & SaveFileByte
                End If
                offset1 += +2
            Loop

            scc.Close()
        Catch ex As Exception

        End Try

    End Sub

    Friend Sub GetGameName()
        Try
            Dim sr As BinaryReader = New BinaryReader(File.Open(FileFound, FileMode.Open))
            sr.BaseStream.Seek(556, SeekOrigin.Begin)
            FlagFind = System.Net.IPAddress.HostToNetworkOrder(sr.ReadInt64())

            Flag = Hex(FlagFind)

            GameNameByte = ""
            GameName = ""
            Dim offset As Integer = 5778
            'get game name
            Do Until GameNameByte = "0" Or GameNameByte = "00"

                sr.BaseStream.Seek(offset, SeekOrigin.Begin)
                GameNameByte = Hex(sr.ReadByte())
                If GameNameByte = "0" Or GameNameByte = "00" Then
                    Exit Do
                Else
                    GameName = GameName & GameNameByte
                End If
                offset += +2
            Loop
            sr.Close()
        Catch ex As Exception

        End Try

    End Sub

    Friend Sub GetProfileID()

        Try
            Dim sr As BinaryReader = New BinaryReader(File.Open(FileFound, FileMode.Open))
            sr.BaseStream.Seek(556, SeekOrigin.Begin)
            FlagFind = System.Net.IPAddress.HostToNetworkOrder(sr.ReadInt64())

            Flag = Hex(FlagFind)

            GameNameByte = ""
            GameName = ""
            Dim offset As Integer = 5778
            'get game name
            Do Until GameNameByte = "0" Or GameNameByte = "00"

                sr.BaseStream.Seek(offset, SeekOrigin.Begin)
                GameNameByte = Hex(sr.ReadByte())
                If GameNameByte = "0" Or GameNameByte = "00" Then
                    Exit Do
                Else
                    GameName = GameName & GameNameByte
                End If
                offset += +2
            Loop
            sr.Close()
        Catch ex As Exception

        End Try
    End Sub
End Module
